
var _url_ = '../table/addTablesInfo.do';
var _url_edit = '../table/updateTablesInfo.do';
var _url_list = '../trans/getShopTransList';
var _url_id = '../table/getTablesById';
var _map = {};
var _pageNum = 1;
var _type ;
var spid="";
  $(function(){
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  console.log(_type);
	  if(_type === "add"){
		 // getTypeListAdd();
		  _showData = {};
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
//		  showEditData();
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
		  getZHInfo();
		  getZHInfo1();
//		  var uid = getCookie("uid");
//		  _map["shopUserId"] = uid;
		  getList();
	  }
  });
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  });
	  $(".search-btn").click(function(){
			 var start =  $("#start").val();
			 var end =  $("#end").val();
			 if(end){
				  end =  addDate(end,1);
			  }
			 _map['startTime'] = start;
			 _map['endTime'] = end;
			 
			 if($("#shoptitle").val()){
				 _map['shopTitle'] = $("#shoptitle").val();
			 }else{
				 _map['shopTitle'] = '';
			 }
			 
			 _pageNum = 1;
			 getList();
	  });
});
  function getList(){
	  _map['pageNum'] = _pageNum;
	  _map['pageSize'] = 100;
	  
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
			  if(res.returnObject.list){
				var pps=   res.returnObject.list[0].allTotalAmount;
				  $("#topicser").text((pps/100));
			  }
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var startRow = res.returnObject.startRow;
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  
			  if(v.tranType == 1 ){
				  typeStr = "订单";
				  if(v.type == 1 ){
					  typeStr+='退款';
				  }else{
					  typeStr+='收入';
				  }
			  }else if(v.tranType == 2 ){
				  typeStr = "商家提现";
			  }else if(v.tranType == 3 ){
				  typeStr = "商家入驻";
				  v.type=2;
			  }
			  html+=' <tr><td>'
// 	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
// 	             +' </td>                                                                                                                  '
// 	             +' <td>'
 	             +(i+startRow)+'</td>                                                                                                             '
 	             +' <td>'+v.shopTitle
 	             +'</td>                                                                                           '
 	             +' <td>'+v.serialNumber
 	             +'</td>                                                                                           '
 	             +' <td >'+(v.type==1?"-":"+")+(v.amount / 100).toFixed(2)+'</td>'
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
 	             +' <td>'+typeStr+'</td>                                                                                                      '
 	             +' <td>'+formatNullData(v.shopUserWx?v.userWxName:v.userWxName)+'</td>                                                                                                      '
 	             +' <td>'+v.createTime+'</td>                                                                                                      '
 	             +' </tr>';
		  });
		  $(".one .layui-table tbody").html(html);
	  });
  }
  function getZHInfo(){
	  _ajax_post_token('../trans/getShopProfit',{},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			 var dd = res.returnObject;
			 $(".money").eq(0).text((dd.charge/100).toFixed(2));
			 $(".money").eq(1).text((dd.amount/100).toFixed(2));
			 $(".money").eq(2).text((dd.amountLeft/100).toFixed(2));
		  }
	  });
  }
  function getZHInfo1(){
	  _ajax_post_token('../sys/getOperateInfo',{},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			  var dd = res.returnObject;
			  $(".price").eq(0).find('span').text((dd.amount/100).toFixed(2));
		  }
	  });
  }
 function getListByStat(_v){
	 if(_v){
		  _map['types'] = _v;
	  }else{
		  _map['types'] = '';
	  }
	  getList();
	 
 }
